# 构建阶段
FROM node:18 AS builder

# 设置工作目录
WORKDIR /app

# 复制package.json和package-lock.json
COPY package*.json ./

# 安装依赖
RUN npm install

# 复制源代码和.env文件
COPY . .

# 构建前端应用
RUN npm run build

# 运行阶段
FROM node:18-slim

WORKDIR /app

# 从构建阶段复制构建产物和必要文件
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/server.js ./
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/.env ./

# 只安装生产环境依赖
RUN npm install --production

# 暴露端口
EXPOSE 9998 9999

# 启动命令
CMD ["node", "server.js"] 